package com.suxin.module.bean;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname MyPoint
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2020/10/16 10:42
 * @Created by ASUS
 */
@Data
public class MyPoint {

    private String metric;

    private Map<String, String> tags = new HashMap<>();

    private Number value;

    private long timestamp;

    public static MetricBuilder builder(String metric) {
        return new MetricBuilder(metric);
    }

    /**
     * 构建器
     */
    public static class MetricBuilder {

        private String metric;

        private Map<String, String> tags = new HashMap<>();

        private Number value;

        private long timestamp;

        public MetricBuilder(String metric) {
            this.metric = metric;
        }

        public MetricBuilder value(Number value) {
            this.value = value;
            return this;
        }

        public MetricBuilder tag(final String tagName, final String value) {
            tags.put(tagName, value);
            return this;
        }

        public MetricBuilder tag(final Map<String, String> tags) {
            this.tags.putAll(tags);
            return this;
        }

        public MyPoint build() {
            MyPoint myPoint = new MyPoint();
            myPoint.metric = this.metric;
            myPoint.tags = this.tags;

            myPoint.timestamp = this.timestamp;
            myPoint.value = this.value;
            return myPoint;
        }

    }

}